//
//  CabinsCell.m
//  lv678
//
//  Created by apple on 15/9/5.
//  Copyright (c) 2015年 lampshade. All rights reserved.
//

#import "CabinsCell.h"
#import "FlightCodeListModel.h"

@interface CabinsCell()
@property (weak, nonatomic) UILabel *lbl_Cabins;

@property (weak, nonatomic) UILabel *lbl_SeatNum;

@property (weak, nonatomic) UILabel *lbl_CabinPrice;

@property (weak, nonatomic) UIButton *btn_Order;

//@property (strong, nonatomic) UITableView *tableView;

@end
@implementation CabinsCell

+ (instancetype)cabinsWithTableView:(UITableView *)tableView{

    static NSString *identity = @"flight_cell";
    
    CabinsCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
    if (cell == nil) {
        cell = [[CabinsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UILabel *cabins = [[UILabel alloc]init];
        [self.contentView addSubview:cabins];
        self.lbl_Cabins = cabins;
        
        UILabel *seatNum = [[UILabel alloc]init];
        [self.contentView addSubview:seatNum];
        self.lbl_SeatNum = seatNum;
        
        UILabel *cabinPrice = [[UILabel alloc]init];
        [self.contentView addSubview:cabinPrice];
        self.lbl_CabinPrice = cabinPrice;
        
        UIButton *order = [[UIButton alloc]init];
        [self.contentView addSubview:order];
        self.btn_Order = order;
        [self.btn_Order setTitle:@"预定" forState:UIControlStateNormal];
        [self.btn_Order setBackgroundColor:[UIColor redColor]];
        self.btn_Order.layer.cornerRadius = 6;
        [self.btn_Order addTarget:self action:@selector(order_Plane) forControlEvents:UIControlEventTouchUpInside];

    }
    return self;
}

- (void)setList:(FlightListModel *)flightListModel setCode:(FlightCodeListModel *)codeModel{
    self.list_model = flightListModel;
    self.code_model = codeModel;
    
}

- (void)setCode_model:(FlightCodeListModel *)code_model{
    _code_model = code_model;
    
    self.lbl_Cabins.font = [UIFont  systemFontOfSize:13.0];
    self.lbl_SeatNum.font = [UIFont systemFontOfSize:13.0];
    self.lbl_CabinPrice.font = [UIFont systemFontOfSize:13.0];
    
    NSArray *first_Class = @[@"F",@"A"];
    NSArray *Bussiness_Class = @[@"B",@"C",@"D",@"J",@"P",@"Z"];
    NSArray *Economy_Class = @[@"W",@"Y",@"T",@"K",@"H",@"M",@"G",@"S",@"L",@"Q",@"U",@"E",@"V",@"R",@"X",@"N"];
    if ([first_Class containsObject:code_model.Code]) {
        self.lbl_Cabins.text = @"头等舱";
    }else if ([Bussiness_Class containsObject:code_model.Code]){
        self.lbl_Cabins.text = @"商务舱";
    }else if ([Economy_Class containsObject:code_model.Code]){
        self.lbl_Cabins.text = @"经济舱";
    }else{
        self.lbl_Cabins.text = @"其它舱";
    }
    if ([code_model.Status isEqualToString:@"A"]) {
        self.lbl_SeatNum.text = @"座位≥9";
    }else{
        self.lbl_SeatNum.text = [NSString stringWithFormat:@"座位剩余%@",_code_model.Status];
    }
    self.lbl_CabinPrice.textColor = [UIColor redColor];
    NSString *price = @"￥";
    self.lbl_CabinPrice.text = [price stringByAppendingString:code_model.Price];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (void)order_Plane{
    
    if ([self.delegate respondsToSelector:@selector(pushViewToOrder:sendData:)]) {
        [self.delegate pushViewToOrder:self.list_model sendData:self.code_model];
    }
}

- (void)layoutSubviews{
    CGFloat controlW = self.bounds.size.width/4;
    CGFloat controlH = self.bounds.size.height;
    CGFloat controlY = 0;
    CGFloat controlX = 15;
    
    self.lbl_Cabins.frame = CGRectMake(controlX, controlY, controlW, controlH);
    self.lbl_SeatNum.frame = CGRectMake(controlX + controlW, controlY, controlW, controlH);
    self.lbl_CabinPrice.frame = CGRectMake(controlX + controlW*2, controlY, controlW, controlH);
    self.btn_Order.frame = CGRectMake(controlX + controlW*3, controlY + 5, controlW - 20, controlH-10);
    
}
@end
